package com.v2future.sjt.collegecheckingattendance.fruit.research;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.event.adapter.EventImgGridAdapter;
import com.v2future.sjt.collegecheckingattendance.fruit.bean.ConditionBean;
import com.v2future.sjt.collegecheckingattendance.fruit.bean.ConditionTypeBean;
import com.v2future.sjt.collegecheckingattendance.fruit.bean.ResearchTypeAddBean;
import com.v2future.sjt.collegecheckingattendance.fruit.bean.ResearchTypeBean;
import com.v2future.sjt.collegecheckingattendance.utils.WidgetUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/1/25.
 */
public class ResearchAdapter extends BaseAdapter{

    List<ConditionBean> dataList;
    Context mContext;
    ConditionTypeBean conditionTypeBean;//成长类型
    ResearchTypeBean researchTypeBean;

    public ResearchAdapter(List<ConditionBean> dataList, Context mContext) {
        this.dataList = dataList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public ConditionTypeBean getConditionTypeBean() {
        return conditionTypeBean;
    }

    public void setConditionTypeBean(ConditionTypeBean conditionTypeBean) {
        this.conditionTypeBean = conditionTypeBean;
    }

    public ResearchTypeBean getResearchTypeBean() {
        return researchTypeBean;
    }

    public void setResearchTypeBean(ResearchTypeBean researchTypeBean) {
        this.researchTypeBean = researchTypeBean;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        ConditionBean bean = dataList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.listitem_research_list, null);
            holder = new ViewHolder();
            holder.key1Tv = (TextView) convertView.findViewById(R.id.tv_key1);
            holder.key2Tv = (TextView) convertView.findViewById(R.id.tv_key2);
            holder.key3Tv = (TextView) convertView.findViewById(R.id.tv_key3);
            holder.value1Tv = (TextView) convertView.findViewById(R.id.tv_value1);
            holder.value2Tv = (TextView) convertView.findViewById(R.id.tv_value2);
            holder.value3Tv = (TextView) convertView.findViewById(R.id.tv_value3);
            holder.imagesGv = (GridView) convertView.findViewById(R.id.gv_release_images);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //图片
        if (null != bean.getImageUrl() && bean.getImageUrl().size() > 0) {
            holder.imagesGv.setVisibility(View.VISIBLE);
            EventImgGridAdapter imageUrlAdapter = new EventImgGridAdapter(mContext, bean.getImageUrl());
            holder.imagesGv.setAdapter(imageUrlAdapter);
        }
        else {
            holder.imagesGv.setVisibility(View.GONE);
        }
        if ("1".equals(researchTypeBean.getResearchSubjectId())) {//论文
            WidgetUtil.setText(holder.key1Tv, "名称：");
            WidgetUtil.setText(holder.key2Tv, "时间：");
            WidgetUtil.setText(holder.key3Tv, "描述：");
            WidgetUtil.setText(holder.value1Tv, bean.getAttr1());
            WidgetUtil.setText(holder.value2Tv, bean.getAttr2());
            WidgetUtil.setText(holder.value3Tv, bean.getAttr6());
        } else if ("2".equals(researchTypeBean.getResearchSubjectId())) {//专著
            WidgetUtil.setText(holder.key1Tv, "名称：");
            WidgetUtil.setText(holder.key2Tv, "出版社名称：");
            WidgetUtil.setText(holder.key3Tv, "描述：");
            WidgetUtil.setText(holder.value1Tv, bean.getAttr1());
            WidgetUtil.setText(holder.value2Tv, bean.getAttr3());
            WidgetUtil.setText(holder.value3Tv, bean.getAttr6());
        } else if ("3".equals(researchTypeBean.getResearchSubjectId())) {//项目
            WidgetUtil.setText(holder.key1Tv, "名称：");
            WidgetUtil.setText(holder.key2Tv, "时间：");
            WidgetUtil.setText(holder.key3Tv, "描述：");
            WidgetUtil.setText(holder.value1Tv, bean.getAttr1());
            WidgetUtil.setText(holder.value2Tv, bean.getAttr3()+"~"+bean.getAttr4());
            WidgetUtil.setText(holder.value3Tv, bean.getAttr7());
        } else if ("4".equals(researchTypeBean.getResearchSubjectId())) {//专利
            WidgetUtil.setText(holder.key1Tv, "名称：");
            WidgetUtil.setText(holder.key2Tv, "级别：");
            WidgetUtil.setText(holder.key3Tv, "描述：");
            WidgetUtil.setText(holder.value1Tv, bean.getAttr2());
            WidgetUtil.setText(holder.value2Tv, bean.getAttr3());
            WidgetUtil.setText(holder.value3Tv, bean.getAttr5());
        } else if ("5".equals(researchTypeBean.getResearchSubjectId())) {//其他
            WidgetUtil.setText(holder.key1Tv, "名称：");
            WidgetUtil.setText(holder.key2Tv, "时间：");
            WidgetUtil.setText(holder.key3Tv, "描述：");
            WidgetUtil.setText(holder.value1Tv, bean.getAttr1());
            WidgetUtil.setText(holder.value2Tv, bean.getAttr2());
            WidgetUtil.setText(holder.value3Tv, bean.getAttr3());
        }
        return convertView;
    }

    public class ViewHolder {
        TextView key1Tv;
        TextView key2Tv;
        TextView key3Tv;
        TextView value1Tv;
        TextView value2Tv;
        TextView value3Tv;
        GridView imagesGv;

    }
}
